﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using td.Core;
using System.Threading;
using CG.Security.Principal;

namespace NorthWind
{
    class NorthWindCommand:td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            var p = WorkBenchSingleTon.WorkBench.GetTabPage("Customers");
            if (p == null)
            {
                NorthWindView view = new NorthWindView();
                WorkBenchSingleTon.WorkBench.AddView(view);
            }
        }
        public override bool IsEnabled
        {
            get
            {
                CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
                bool r =  (cp.IsAuthorized("Test 1") || cp.IsInRole("Admin"));
                return   r&&( null== WorkBenchSingleTon.WorkBench.GetTabPage("Customers"));

            }
            set
            {
                base.IsEnabled = value;
            }
        }
    }
}
